home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
TransSkel.cpt
/
TinyEdit.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-01-08
|
4KB
|
204 lines
{ TinyEdit - Minimal TransEdit Demonstration.}
{ The project should include TinyEdit.pas (this file), TransEdit.pas,}
{ FakeAlert.pas, TransSkelpas (or a project made from TransSkelpas)}
{ MacPasLib and MacTraps.}
{ 8 November 1986 Paul DuBois}
{ 8 January 1987 Ported to LightSpeed Pascal by Owen Hartnett }
{ Ωhm Software Company, 163 Richard Drive, Tiverton, RI 02878 }
PROGRAM TinyEdit;
USES
TransEditPas, TransSkelPas;
CONST
aboutAlrt = 1000; { "About..." alert number }
{ File menu item numbers }
new = 1; { begin new window }
open = 2; { open existing file }
close = 3; { close window }
quit = 5;
{ Edit menu item numbers }
undo = 1;
cut = 3;
copy = 4;
paste = 5;
clear = 6;
VAR
lastFront, editWind : WindowPtr; { keeps track of front window }
{ non-nil if edit window open }
fileMenu, editMenu : MenuHandle;
{ Set File/Edit menu items according to type of front window.}
{ The general behavior is:}
{ New and Open enabled if an edit window is not open, otherwise they}
{ are disabled.}
{ Close enabled when an edit or DA window is in front (i.e.,}
{ when there's a window at all).}
{ Undo disabled when the edit window is in front.}
PROCEDURE SetMenus;
BEGIN
DisableItem(fileMenu, close); { assume no window at all }
EnableItem(editMenu, undo);
IF FrontWindow <> NIL THEN
BEGIN
EnableItem(fileMenu, close);
IF (IsEWindow(FrontWindow)) THEN { the edit window's in front }
DisableItem(editMenu, undo);
END;
IF editWind = NIL THEN
BEGIN
EnableItem(fileMenu, new);
EnableItem(fileMenu, open);
END
ELSE
BEGIN
DisableItem(fileMenu, new);
DisableItem(fileMenu, open);
END;
END;
{ Got an activate or deactivate. It doesn't matter which, really.}
{ Set the text menus appropriately for the front window, and draw}
{ the menu bar, as these menus might change state from enabled to}
{ disabled or vice-versa.}
PROCEDURE Activate (active : Boolean);
BEGIN
SetMenus;
END;
{ Close selected from File menu, or close box of edit window was}
{ clicked.}
PROCEDURE myClose;
BEGIN
IF (EWindowClose(editWind)) THEN
editWind := NIL;
SetMenus;
END;
{ Make a new edit window. Set the title to "Untitled" if not bound}
{ to file, so that the window titling works the same whether}
{ TransEdit is compiled in single or multiple window mode.}
PROCEDURE MakeWind (bindToFile : Boolean);
VAR
r : Rect;
BEGIN
SetRect(r, 4, 45, 504, 335);
editWind := NewEWindow(r, '', false, WindowPtr(-1), true, longint(0), bindToFile);
IF editWind <> NIL THEN
BEGIN
IF NOT bindToFile THEN
SetWTitle(editWind, 'Untitled');
ShowWindow(editWind);
END;
END;
{ File menu handler}
PROCEDURE DoFileMenu (item : integer);
VAR
theWind : WindowPtr;
myPeek : WindowPeek;
BEGIN
theWind := FrontWindow;
CASE item OF
new :
MakeWind(false);
open :
MakeWind(true);
close :
IF IsEWindow(theWind) THEN
myClose
ELSE
BEGIN
myPeek := WindowPeek(theWind);
CloseDeskAcc(myPeek^.windowKind);
END;
quit :
IF ClobberEWindows = true THEN
SkelWhoa;
OTHERWISE
END;
SetMenus;
END;
{ Handle selection of About… item from Apple menu}
PROCEDURE DoAbout;
VAR
ignore : integer;
BEGIN
ignore := Alert(aboutAlrt, NIL);
END;
{ Background procedure. Check front window, reset menus if it}
{ changes.}
PROCEDURE CheckFront;
BEGIN
IF FrontWindow <> lastFront THEN
BEGIN
SetMenus;
lastFront := FrontWindow;
END;
END;
BEGIN
lastFront := NIL;
editWind := NIL;
{ Initialize TransSkel, create menus and install handlers.}
SkelInit;
TransEditInit;
SkelApple('About TinyEdit...', @DoAbout);
fileMenu := NewMenu(1000, 'File');
AppendMenu(fileMenu, 'New/N;Open.../O;(Close/K;(-;Quit/Q');
SkelMenu(fileMenu, @DoFileMenu, NIL);
editMenu := NewMenu(1001, 'Edit');
AppendMenu(editMenu, 'Undo/Z;(-;Cut/X;Copy/C;Paste/V;Clear');
SkelMenu(editMenu, @EWindowEditOp, NIL);
{ Do TransEdit-specific setup: set creator for any files created,}
{ set default event notification procedures for new windows.}
SetEWindowProcs(NIL, NIL, @Activate, @myClose);
{ Process events until user quits,}
{ then clean up and exit}
SkelBackground(@CheckFront);
SkelMain;
SkelClobber;
END.